package com.wh.minio.container.service;

import com.wh.minio.container.common.CommonResult;
import com.wh.minio.container.common.Constants;
import com.wh.minio.container.dao.BucketDao;
import com.wh.minio.container.dto.BucketDTO;
import io.minio.errors.MinioException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONObject;
import org.xmlpull.v1.XmlPullParserException;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.List;


/***
 * RootService是minio桶资源，基于REST-FUL规则设计风格。
 *
 * 1. http://ip:host/minio/bucketservice/list,         代表： 获取minio《桶》资源目录信息。
 * 2. http://ip:host/minio/bucketservice/detail/xxxx,  代表： 获取minio《桶》资源详情信息。
 *
 *
 * @Package com.wh.technology.xbox.common
 * @author 谢泽鹏
 * @date 2016年11月07日 下午15:10
 * @Copyright 个人版权所有
 * @Company 贵州万华科技有限公司Copyright (c) 2016
 * @version V1.0
 */
@Path("/bucketservice")
public class BucketService {


    private static final Log logger = LogFactory.getLog(BucketService.class);


    private BucketDao bucketDao = new BucketDao();

    @GET
    @Path("/list")
    @Produces({MediaType.APPLICATION_JSON})
    public CommonResult listBuckets() {
        CommonResult commonResult = new CommonResult();
        try{
            commonResult.setCode(Constants.CODE_SUCCESS);
            commonResult.setMessage("获取Bucket桶成功！");
            commonResult.setResult(bucketDao.listBuckets());
        } catch (Exception e){
            e.printStackTrace();
            commonResult.setCode(Constants.CODE_FAIL);
            commonResult.setMessage("获取Bucket桶失败！");
            commonResult.setResult(new JSONObject());
            logger.error("Exception:  " + e.getMessage());
        }
            return commonResult;
    }

    @GET
    @Path("/detail")
    @Produces({MediaType.APPLICATION_JSON})
    public CommonResult detail() {
        CommonResult commonResult = new CommonResult();
        try{
            commonResult.setCode(Constants.CODE_SUCCESS);
            commonResult.setMessage("获取Bucket桶详情成功！");
            commonResult.setResult(new JSONObject());
        } catch (Exception e){
            e.printStackTrace();
            commonResult.setCode(Constants.CODE_FAIL);
            commonResult.setMessage("获取Bucket桶详情失败！");
            commonResult.setResult(new JSONObject());
            logger.error("Exception:  " + e.getMessage());
        }
            return null;
    }





}
